package chapter7.No7_2_线程组.a线程对象关联线程组_1级关联;

/**
 * !向线程组中添加2个线程
 *
 * @author liujian
 * @version 2016/12/8 0008
 */
public class Main {
    static class MyThread implements Runnable {
        public void run() {
            System.out.println("进入Run" + System.currentTimeMillis());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("退出Run" + System.currentTimeMillis());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        // 添加线程组名为“我的第一个线程组A”， 向线程组中加入线程a
        ThreadGroup group = new ThreadGroup("我的第一个线程组A");
        MyThread run = new MyThread();
        Thread a = new Thread(group, run);
        Thread b = new Thread(group, run);
        a.start();
        b.start();
        Thread.sleep(200);
        System.out.println("活动的线程：" + group.activeCount());
        System.out.println("线程组的名字：" + group.getName());
    }
}
